import { createStore, applyMiddleware, compose } from 'redux'
// a(b(c(1,2,3)))  => compose('a','b','c')(1,2,3)

// 中间件 异常操作 返回function
import thunk from 'redux-thunk'

import reducer from './reducers/countReducer'

/* function mym(store) {
  return function (next) {
    return function (action) {
      console.log('你好');
      next(action)
    }
  }
} */

// 自定义中间件 一般在公司中用它来记录日志
const mym = store => next => action => {
  console.log(action,store)
  next(action)
}

// 配置chrome中的redux扩展可视化操作
const composeEnhancers =
  typeof window === 'object' &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose
const enhancer = composeEnhancers(
  applyMiddleware(thunk, mym)
)

export default createStore(
  reducer,
  enhancer
)